package io.renren.common.vo;

import java.util.List;

import com.github.pagehelper.Page;

public class PageInfo<T> extends RV {
	public Boolean success = true;
	// 当前页(页码)
	private int currPage;
	// 每页的数量
	private int pageSize;
	// 当前页的数量
//	private int pageNum;
	// 总记录数
	private long totalCount;
	// 总页数
	private int totalPage;
	// 结果集
	private List<T> list;
	// 编码
	private String code;
	// 信息
	private String msg;


	/**
	 * 包装page对象
	 * 
	 * @param list
	 * @param code
	 * @param msg
	 */
	public PageInfo(List<T> list, String code, String msg) {
		this(list);
		this.setCode(code);
		this.setMsg(msg);

	}


	/**
	 * 包装Page对象
	 *
	 * @param list
	 *            page结果
	 */
	@SuppressWarnings("rawtypes")
	public PageInfo(List<T> list) {
		this.setCode("200");
		this.setMsg("success");
		if (list instanceof Page) {
			
			Page page = (Page) list;
			this.currPage = page.getPageNum();
			this.totalCount = page.getTotal();
			this.totalPage = page.getPages();
			this.list = page;
			this.pageSize = page.size();
			this.pageSize = page.getPageSize();
		} else {
			this.list = list;
			this.currPage = 1;
			this.totalCount = list.size();
			this.totalPage = 1;
			this.pageSize = list.size();
		}
	}



	public List<T> getList() {
		return list;
	}

	/**
	 * pageSize
	 *
	 * @return the pageSize
	 * @since 1.0.0
	 */

	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize
	 *            the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
}
